package srping.test.web;

import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.test.context.ContextConfiguration;

import spring.test.service.DaoHelloService;

/**
 * 
 * @author likunran
 *
 */
public class HelloSpringSoruce {
	

	
	
	public void printHello(){
	             ApplicationContext context = new ClassPathXmlApplicationContext("spring-config-source.xml");
	             DaoHelloService helloApi = (DaoHelloService)context.getBean("hello");
	              //3、执行业务逻辑
	             helloApi.doSomeThing();
	}
	
	
	public void getBeanByType(){
		  System.out.println("getBeanByType");
		  ApplicationContext context = new ClassPathXmlApplicationContext("spring-config-source1.xml");
				    //根据类型获取bean
		  DaoHelloService helloApi = (DaoHelloService)context.getBean("hello");
           //3、执行业务逻辑
          helloApi.doSomeThing();
	}
	
	

	public void getBeanByName(){
		  System.out.println("getBeanByName");
		  ApplicationContext context = new ClassPathXmlApplicationContext("spring-config-source2.xml");
				    //根据类型获取bean
		  DaoHelloService helloApi = (DaoHelloService)context.getBean("hello");
           //3、执行业务逻辑
          helloApi.doSomeThing();
          
	}
	
	
	public void getBeanByAlias(){
		 System.out.println("getBeanByAlias");
		 ApplicationContext context = new ClassPathXmlApplicationContext("spring-config-source3.xml");
		    //根据类型获取bean
		 DaoHelloService helloApi = (DaoHelloService)context.getBean("alias21");
		 helloApi.doSomeThing("getBeanByAlias");
	}
	
	
	public void getBeanByAliasCount(){
		 System.out.println("getBeanByAlias");
		 ApplicationContext context = new ClassPathXmlApplicationContext("spring-config-source3.xml");
		 String[] bean1Alias = context.getAliases("hello");
		    System.out.println("=======spring-config-source3.xml bean1 别名========");
		    for(String alias : bean1Alias) {
		        System.out.println(alias);
		    }
		
	}
	
	
	
	public void getBeanByAliasCount2(){
		 System.out.println("getBeanByAlias");
		 ApplicationContext context = new ClassPathXmlApplicationContext("spring-config-source4.xml");
		 String[] bean1Alias = context.getAliases("hello");
		    System.out.println("=======spring-config-source3.xml bean1 别名========");
		    for(String alias : bean1Alias) {
		        System.out.println(alias);
		    }
		
	}


	
	@Test
	public void getBeanByAliasCount5() {
		 System.out.println("getBeanByAlias");
		 ApplicationContext context = new ClassPathXmlApplicationContext("spring-config-source5.xml");
		 DaoHelloService helloApi = (DaoHelloService)context.getBean("bean2");
          //3、执行业务逻辑
		 System.out.println("hello");
		  helloApi.doSomeThing();
		
	}
	

}
